package com.softa.common.sysconfig.mybatis.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.lang.reflect.Field;

/**
 * description goes here.
 *
 * @author 杨磊
 * @date 2019/5/6 21:36
 * @since 1.0
 **/
@Data
public class BootBaseMapperDTO {

    private String tableName;

    private String key;

    private String value;

    public BootBaseMapperDTO(){

    }

    public BootBaseMapperDTO(Class<? extends Object> clazz, String value){
        setData(clazz);
        this.value = value;
    }

    public void setData(Class<? extends Object> clazz){
        TableName tableNameA = clazz.getAnnotation(TableName.class);
        tableName = tableNameA.value();
        Field[] fields = clazz.getDeclaredFields();
        for(Field field : fields){
            Boolean isflag = field.isAnnotationPresent(TableId.class);
            if(isflag){
                TableId tableId = field.getAnnotation(TableId.class);
                key = tableId.value();
                break;
            }
        }
    }

}
